﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using Repositories.Interfaces;
using Repositories.Implementations;


namespace Repositories
{
  public static class DIHelper
  {
    private static IUnityContainer myContainer = new UnityContainer();

    /// <summary>
    /// Configures this instance.
    /// </summary>
    public static void Configure()
    {
        myContainer.RegisterType<IMealRepository, MealRepository>((new PerThreadLifetimeManager()));
        myContainer.RegisterType<ICategoryRepository, CategoryRepository>((new PerThreadLifetimeManager()));
        myContainer.RegisterType<IComboRepository, ComboRepository>((new PerThreadLifetimeManager()));
        myContainer.RegisterType<IGroupMealRepository, GroupMealRepository>((new PerThreadLifetimeManager()));
        myContainer.RegisterType<IUserLoginRepository, UserLoginRepository>((new PerThreadLifetimeManager()));
        myContainer.RegisterType<ICustomersRepository, CustomersRepository>((new PerThreadLifetimeManager()));
        
    }

    /// <summary>
    /// Resolves this instance.
    /// </summary>
    /// <typeparam name="T">Object need to be resolved</typeparam>
    /// <returns>Resolved objects.</returns>
    public static T Resolve<T>()
    {      
      return myContainer.Resolve<T>();
    }

    /// <summary>
    /// Resolves this instance.
    /// </summary>
    /// <typeparam name="T">Object need to be resolved</typeparam>
    /// <param name="name">The name.</param>
    /// <returns>Resolved objects.</returns>
    public static T Resolve<T>(string name)
    {
      return myContainer.Resolve<T>(name);
    }
  }
}
